package com.bblocks.enums;

import com.bblocks.config.SwaggerDisplayEnum;
import com.bblocks.exception.ServiceException;
import lombok.Getter;

@Getter
@SwaggerDisplayEnum(index = "type", name = "name")
public enum AppPlatformTypeEnum {
	Android(1, "android"),
	Ios(2, "ios"),
	Wx(3, "微信小程序"),

	H5(11, "h5"),

	Unknown(-1, "未知"),//
	;

	//订单状态:0=初始,1=待付款,2=待发货,4=配送中,5=待收货,6=已完成,9=已取消
	private Integer type;
	private String name;

	AppPlatformTypeEnum(Integer type, String name) {
		this.type = type;
		this.name = name;
	}


	@Override
	public String toString() {
		return String.valueOf(type) + ":" + name;
	}

	private static AppPlatformTypeEnum[] appPlatformTypeEnums =  AppPlatformTypeEnum.values();
	public static AppPlatformTypeEnum getAppPlatformTypeEnum(Integer type) {
		if(type == null){
			return AppPlatformTypeEnum.Unknown;
		}
		for (AppPlatformTypeEnum c : appPlatformTypeEnums) {
			if (c.getType().equals(type) ) {
				return c;
			}
		}

		throw new ServiceException("无此平台："+type);
	}
}
